#
# Makefile to make the file libclientserver.a, containing
# connection.o and server.o
#

CXX		 = g++
CXXFLAGS	 = -ggdb  -Wall -W -Werror -pedantic-errors
CXXFLAGS	+= -Wmissing-braces -Wparentheses -O2
# The following option cannot be used since some of the socket
# macros give warnings on "old-style-cast"
#CXXFLAGS	+= -Wold-style-cast


SRC	= $(wildcard *.cc)

.PHONY: all clean client server serverdisc

all: client server 

server: server.o newsgroup.o myserver.o servernntp.o connection.o nntp.o database.o databasedisc.o
	$(CXX) $(CXXFLAGS) -o ../bin/$@ $^
	rm servernntp.o
	make serverdisc
serverdisc: CXXFLAGS += -DDISC
serverdisc: server.o newsgroup.o myserver.o servernntp.o connection.o nntp.o database.o databasedisc.o
	$(CXX) $(CXXFLAGS) -o ../bin/$@ $^

client: clientnntp.o connection.o nntp.o client.o
	$(CXX) $(CXXFLAGS) -o ../bin/$@ $^

server.o: server.cc server.h connection.h
database.o: database.cc database.h
newsgroup.o: newsgroup.cc newsgroup.h
myserver.o: myserver.cc servernntp.h
servernntp.o: servernntp.cc newsgroup.h server.h nntp.h
connection.o: connection.cc connection.h
nntp.o: nntp.cc nntp.h
client.o: client.cc
clientnntp.o: clientnntp.cc clientnntp.h
databasedisc.o: databasedisc.cc database.h

#client: client.o libclientserver.a
#	$(CXX) $(CXXFLAGS) -L. -lclientserver client.o -o $@

#client.o: client.cc libclientserver.a

# Create the library; ranlib is for Darwin and maybe other systems.
# Doesn't seem to do any damage on other systems.

# libclientserver.a: connection.o server.o nntp.o newsgroup.o servernntp.o clientnntp.o
#	ar crv libclientserver.a connection.o server.o nntp.o newsgroup.o servernntp.o clientnntp.o
#	ranlib libclientserver.a

clean:
	$(RM) *.o
	$(RM) ../bin/client ../bin/server ../bin/serverdisc

#cleaner: clean
#	$(RM) libclientserver.a

#%.d: %.cc
#	@set -e; rm -f $@; \
#	 $(CXX) -MM $(CXXFLAGS) $< > $@.$$$$; \
#	 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
#	 rm -f $@.$$$$

#include $(SRC:.cc=.d)
